package core

import (
	"github.com/go-ini/ini"
	"github.com/google/uuid"
	"log"
	"strings"
)

var (
	HttpPort             = "9307"                                            //默认启动端口
	LogFile              = "info.log"                                        //默认日志路径
	HealthyTaskSpec      = "*/1 * * * * ?"                                   //默认健康检查
	Secret               = strings.Replace(uuid.New().String(), "-", "", -1) //默认秘钥
	DefaultFailureFactor = 2.0                                               // 默认降权因子
)

func init() {
	cfgs, err := ini.Load("config.ini")
	if err != nil {
		log.Println(err.Error())
		return
	}
	hp := cfgs.Section("").Key("httpPort").Value()
	if hp != "" {
		HttpPort = hp
	}
	lf := cfgs.Section("").Key("logFile").Value()
	if lf != "" {
		LogFile = lf
	}
	hts := cfgs.Section("").Key("healthyTaskSpec").Value()
	if hts != "" {
		HealthyTaskSpec = hts
	}
	se := cfgs.Section("").Key("secret").Value()
	if se != "" {
		Secret = se
	}
	dff, _ := cfgs.Section("").Key("defaultFailureFactor").Float64()
	if dff != 0 {
		DefaultFailureFactor = dff
	}
}
